import QtQuick 2.15
import QtQuick.Controls 2.15

SubView1 {
    id: root
    width: 532
    height: 349

    AdditionalLightBar
    {
        id:additionalLight
    }
    signal stopTimmer;
    signal startTimer;
    onStopTimmer: {
        collectWeightTimer.running=false
    }
    onStartTimer: {
        collectWeightTimer.running=true
    }
    Component.onDestruction: {
        collectWeightTimer.destroy()
    }
    Component.onCompleted: {
        //cmbUnit.currentIndex = cmbUnit.find(mymodbus.unit);
        cmbUnit.currentIndex = cmbUnit.find("kg");
    }
    Rectangle
    {
        id:displayPanel
        x: 1
        y: 36
        width: 531
        height: 312
        color:"transparent"
        border.color: "white"

        //彩屏电量。
        Button
        {
            id:btnBat
            width: 70
            height: 50
            x: 4
            y: 4
            background: Rectangle{
                border.width: 0
                color: "#7584C2"
            }

            text: mymodbus.batNew
            font.pixelSize: 25
            palette.buttonText: "white"
            enabled: false
            onClicked: {
            }
        }


        Column
        {
            x: 423
            y: 10
            spacing: 5
            Button
            {
                id:btnSetZero
                width: 100
                height: 50
//                background: Rectangle{
//                    border.width: 0
//                    color: "#7584C2"
//                }
                background: Rectangle{
                    border.width: btnSetZero.down?1: 0
                    color: btnSetZero.down?"#FF614B": "#C070B0"
                    border.color: "#F0D070"
                }

                text: qsTr("清零")
                font.pixelSize: 25
                palette.buttonText: "white"

                onClicked: {
                    //mymodbus.setZeroWeight1(mymodbus.weightNew)
                    //mymodbus.slotZeroWeight();
                    mymodbus.op_zero();
                }
            }

            MyComboBox
            {
                id:cmbUnit
                width: 100
                height: 45
//                Layout.row:0
//                Layout.column:1
//                Layout.preferredWidth: btnWidth
//                Layout.preferredHeight: btnHeight
                borderColor:"white"
                fillColor:"#0A3653"
                model:["ug","mg","g","kg","Mg","t","lb","dyne","kdyne","oz","TONNE"]
                //currentIndex: cmbUnit.find(mymodbus.unit)
                onActivated: {
                    mymodbus.setUnit(cmbUnit.currentText)
                }
            }
        }

        Text
                {
                    id: weight
                    text: mymodbus.weightNew+mymodbus.unit//qsTr("999999")
                    color: "white"
                    font.pixelSize: 80
                    width:parent.width
                    height:parent.height
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
//        Text
//        {
//            id:unit
//            x: 421
//            y: 124
//            text:qsTr("g")
//            color: "white"
//            font.pixelSize: 50
//        }


    }

//    Timer{
//        id: collectWeightTimer
//        running: true
//        repeat: true
//        interval: 100//mymodbus.collectTime
//        onTriggered: {
//            weight.text = mymodbus.weightNew+mymodbus.unit
//            console.log("update weight")
//        }
//    }
}

